import { MigrationInterface, QueryRunner } from 'typeorm'

export class CreateUserHistory1684723200001 implements MigrationInterface {
  public async up(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`
      CREATE TABLE c_user_history (
        id INT AUTO_INCREMENT PRIMARY KEY,
        user_id INT NOT NULL COMMENT '用户ID',
        editor_id INT NOT NULL DEFAULT 0 COMMENT '编辑者ID',
        editor_name VARCHAR(255) DEFAULT '' COMMENT '编辑者姓名',
        status_before INT NOT NULL DEFAULT 0 COMMENT '修改前状态',
        status_after INT NOT NULL DEFAULT 0 COMMENT '修改后状态',
        mark_before TEXT COMMENT '修改前备注',
        mark_after TEXT COMMENT '修改后备注',
        changes TEXT COMMENT '其他变更内容',
        created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP COMMENT '创建时间',
        updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP COMMENT '更新时间',
        INDEX idx_user_id (user_id),
        INDEX idx_editor_id (editor_id),
        INDEX idx_created_at (created_at)
      ) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4 COLLATE=utf8mb4_unicode_ci COMMENT='用户编辑历史表';
    `)
  }

  public async down(queryRunner: QueryRunner): Promise<void> {
    await queryRunner.query(`DROP TABLE IF EXISTS c_user_history`)
  }
} 